home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / futils / futils~1 / src / misc1s.zoo / misc1 / combine / util.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-23  |  4.3 KB  |  149 lines

  1. /*
  2.  * Type extensions and abbreviations This creates the HOS environment. Such
  3.  * things as bit_type remain unexported.
  4.  */
  5.  
  6. #define uint   unsigned int
  7.  
  8. #define ABS(x)   ( (x) >= 0 ? (x) : -(x) )
  9. #define MOD(x,y) ( (x) % (y) )
  10. #define mod(x,y) MOD(x,y)
  11.  
  12. #define  min(_a,_b) ( (_a) < (_b) ? (_a) : (_b) )
  13. #define  max(_a,_b) ( (_a) > (_b) ? (_a) : (_b) )
  14.  
  15. #define NULLC     '\0'
  16. #define NEWLINE   '\n'
  17. #define NULL_PTR  0
  18.  
  19. #define bool int
  20. #define TRUE 1
  21. #define FALSE 0
  22. /* All of the following macros deal with a doubly-linked list (dll).
  23.  *
  24.  * A 'dll' is a doubly-linked list of nodes, where one endof the list is
  25.  * designated the "head" and the other endis designated the "tail". A 'dll'
  26.  * is composed of a head pointer, a tail pointer, and zero or more nodes
  27.  * each containing pointers to the next and previous nodes in the 'dll'. The
  28.  * head pointer points to the first node in the 'dll' which is linked
  29.  * through the "next" pointer fields in the nodes. The tail pointer points
  30.  * to the last node in the 'dll' which is linked through the "previous"
  31.  * pointer fields in the nodes. Each list is terminated by a NULL_PTR. If
  32.  * either the "head" pointer or the "tail" pointer is a NULL_PTR, then the
  33.  * 'dll' is empty.
  34.  *
  35.  * All of the macros share the following parameter definitons.
  36.  *
  37.  * Parameter definitions:
  38.  * ----------------------
  39.  *
  40.  * _head_ptr  (input) node_type *
  41.  *           The head pointer of the 'dll'.
  42.  *
  43.  * _tail_ptr  (input) node_type *
  44.  *           The tail pointer of the 'dll'.
  45.  *
  46.  * _node_ptr  (input) node_type *
  47.  *           The variable which points to the node the insert into the
  48.  *         'dll' or the variable to receive a pointer to the node removed from the
  49.  *           'dll'. If the 'dll' is empty, then this variable is NULL_PTR.
  50.  *
  51.  * _next_ptr  (input) field_name_in_nd
  52.  *           The name of the next pointer field in the node structure.
  53.  *
  54.  * _prev_ptr  (input) field_name_in_nd
  55.  *           The name of the previous pointer field in the node structure.
  56.  */
  57.  
  58. /*
  59.  *
  60.  *   deq_head_dll -- Remove a node from the front of a 'dll'.
  61.  *
  62.  */
  63.  
  64. #define deq_head_dll( _head_ptr, _tail_ptr, _node_ptr, _next_ptr, _prev_ptr ) \
  65.  \
  66.    (_node_ptr) = (_head_ptr) ; \
  67.    if ( (_node_ptr) != NULL_PTR ) { \
  68.       (_head_ptr) = (_node_ptr) -> _next_ptr ; \
  69.       if ( (_head_ptr) == NULL_PTR ) { \
  70.      (_tail_ptr) = NULL_PTR ; \
  71.       } else { \
  72.      (_head_ptr) -> _prev_ptr = NULL_PTR ; \
  73.       } ; \
  74.    }
  75.  
  76. /*
  77.  *
  78.  *   deq_tail_dll -- Remove a node from the tail of a 'dll'.
  79.  *
  80.  */
  81.  
  82. #define deq_tail_dll( _head_ptr, _tail_ptr, _node_ptr, _next_ptr, _prev_ptr ) \
  83.  \
  84.    (_node_ptr) = (_tail_ptr) ; \
  85.    if ( (_node_ptr) != NULL_PTR ) { \
  86.       (_tail_ptr) = (_node_ptr) -> _prev_ptr ; \
  87.       if ( (_tail_ptr) == NULL_PTR ) { \
  88.      (_head_ptr) = NULL_PTR ; \
  89.       } else { \
  90.      (_tail_ptr) -> _next_ptr = NULL_PTR ; \
  91.       } ; \
  92.    }
  93.  
  94. /*
  95.  *
  96.  *   enq_head_dll -- Add a node to the head of an 'dll'.
  97.  *
  98.  */
  99.  
  100. #define enq_head_dll( _head_ptr, _tail_ptr, _node_ptr, _next_ptr, _prev_ptr ) \
  101.  \
  102.    (_node_ptr) -> _prev_ptr = NULL_PTR ; \
  103.    if ( _head_ptr == NULL_PTR ) { \
  104.       _tail_ptr = (_node_ptr) ; \
  105.       (_node_ptr) -> _next_ptr = NULL_PTR ; \
  106.    } else { \
  107.       (_node_ptr) -> _next_ptr = (_head_ptr) ; \
  108.       (_head_ptr) -> _prev_ptr = (_node_ptr) ; \
  109.    } ; \
  110.    (_head_ptr) = (_node_ptr)
  111.  
  112. /*
  113.  *
  114.  *   enq_tail_dll -- Add a node to the tail of a 'dll'.
  115.  *
  116.  */
  117.  
  118. #define enq_tail_dll( _head_ptr, _tail_ptr, _node_ptr, _next_ptr, _prev_ptr ) \
  119.  \
  120.    if ( (_head_ptr) == NULL_PTR ) { \
  121.       (_head_ptr) = (_tail_ptr) = (_node_ptr) ; \
  122.       (_node_ptr) -> _next_ptr  = (_node_ptr) -> _prev_ptr = NULL_PTR ; \
  123.    } else { \
  124.       (_tail_ptr) -> _next_ptr = (_node_ptr) ; \
  125.       (_node_ptr) -> _prev_ptr = (_tail_ptr) ; \
  126.       (_tail_ptr)              = (_node_ptr) ; \
  127.       (_node_ptr) -> _next_ptr = NULL_PTR ; \
  128.    }
  129.  
  130. /*
  131.  *
  132.  *   rem_dll -- Remove a node from anywhere in a 'dll'.
  133.  *
  134.  */
  135.  
  136. #define rem_dll( _head_ptr, _tail_ptr, _node_ptr, _next_ptr, _prev_ptr ) \
  137.  \
  138.    if ( (_node_ptr) -> _prev_ptr == NULL_PTR ) { \
  139.       (_head_ptr) = (_node_ptr) -> _next_ptr ; \
  140.    } else { \
  141.       (_node_ptr) -> _prev_ptr -> _next_ptr = (_node_ptr) -> _next_ptr ; \
  142.    } ; \
  143.  \
  144.    if ( (_node_ptr) -> _next_ptr == NULL_PTR ) { \
  145.       (_tail_ptr) = (_node_ptr) -> _prev_ptr ; \
  146.    } else { \
  147.       (_node_ptr) -> _next_ptr -> _prev_ptr = (_node_ptr) -> _prev_ptr ; \
  148.    }
  149.